Home:ALL Converter>How can I store many variables in one file, and access those variables from a different file?

How can I store many variables in one file, and access those variables from a different file?

Ask Time:2012-06-22T04:47:11         Author:Thor Correia

Json Formatter

I want to create a 'mini-database'. I want to have one file with lots of variables, and be able to take those variables from the file, while also being able to add variables to the file? For example, lets suppose this is the 'mini-db':

hello = ['a', 'b', 'c']
world = ['d', 'e', 'f']
foo = ['g', 'h', 'i']

and from a different file, I would like to say something like:

print MiniDB.hello[0]

So basically access the variable. Also, I would need to write variables INTO the file. so something like this:

MiniDB.bar = ['j', 'k', 'l']

How can I do this?

Author:Thor Correia,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/11146483/how-can-i-store-many-variables-in-one-file-and-access-those-variables-from-a-di
Ignacio Vazquez-Abrams :

shelve is the easiest way to do this. Mind the concurrency restrictions though.",
2012-06-21T20:52:01
yy